package baseline;

import java.util.Vector;
import java.io.*;

public class FileParser {
  public static class FPException extends Exception {
    public FPException(final String error) {
      super(error);
    }
  }

  protected Vector<String> words_;
  protected Vector<String> tags_;

  public FileParser() {
    words_ = new Vector<String>();
    tags_ = new Vector<String>();
  }

  public void parseFile(String fileName) throws FPException {
    FileReader fr = null;
    try {
      fr = new FileReader(new File(fileName));
    } catch (FileNotFoundException e) {
      throw new FPException(e.getMessage());
    }

    BufferedReader in = new BufferedReader(fr);
    String str;
    while (true) {
      try {
        str = in.readLine();
      } catch (IOException e) {
        throw new FPException(e.getMessage());
      }

      if (str == null)
        break;

      String[] tokens = str.split(" ");
      String currentTag = tokens[0];
      String currentWord = str.substring(currentTag.length() + 1);

      words_.add(currentWord.toLowerCase());
      tags_.add(currentTag);
    }
  }
}
